package web.suzy.oj.service.admin.announcement.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;
import web.suzy.oj.common.exception.StatusFailException;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.manager.admin.announcement.AdminAnnouncementManager;
import web.suzy.oj.pojo.entity.common.Announcement;
import web.suzy.oj.pojo.vo.AnnouncementVO;
import web.suzy.oj.service.admin.announcement.AdminAnnouncementService;

import javax.annotation.Resource;

/**
 * YangSuzy 软件工作室
 * 类名: AdminAnnouncementServiceImpl
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/11/25 20:30
 */
@Service
public class AdminAnnouncementServiceImpl implements AdminAnnouncementService {
    @Resource
    private AdminAnnouncementManager adminAnnouncementManager;

    /**
     * 方法名: getAnnouncementList
     * 描述: 获取公告列表
     *
     * @param limit       每页显示数目
     * @param currentPage 当前页
     * @return web.suzy.oj.common.result.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < web.suzy.oj.pojo.vo.AnnouncementVO>>
     * @date 2022/11/25 20:31
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<IPage<AnnouncementVO>> getAnnouncementList(Integer limit, Integer currentPage) {
        return ResultBean.successResponse(adminAnnouncementManager.getAnnouncementList(limit, currentPage));
    }

    /**
     * 方法名: addAnnouncement
     * 描述: 管理员添加公告
     *
     * @param announcement
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/25 20:32
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<Void> addAnnouncement(Announcement announcement) {
        try {
            adminAnnouncementManager.addAnnouncement(announcement);
            return ResultBean.successResponse();
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        }
    }

    /**
     * 方法名: updateAnnouncement
     * 描述: 管理员更新公告
     *
     * @param announcement
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/25 20:32
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<Void> updateAnnouncement(Announcement announcement) {
        try {
            adminAnnouncementManager.updateAnnouncement(announcement);
            return ResultBean.successResponse();
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        }
    }

    /**
     * 方法名: deleteAnnouncement
     * 描述: 管理员删除公告
     *
     * @param aid
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/25 20:32
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<Void> deleteAnnouncement(Long aid) {
        try {
            adminAnnouncementManager.deleteAnnouncement(aid);
            return ResultBean.successResponse();
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        }
    }
}
